package com.mtsmda.designPattern1.creational.prototype;

import java.util.HashMap;
import java.util.Map;

public class ComputerPrototype {

	private static Map<String, Computer> computerMap = new HashMap<String, Computer>();

	static {
		loadCache();
	}

	private static void loadCache() {
		Computer pc = new PC();
		computerMap.put("1", pc);

		Computer notebook = new Notebook();
		computerMap.put("2", notebook);

		Computer netbook = new Netbook();
		computerMap.put("3", netbook);
	}

	public static Computer getComputer(String id)
			throws CloneNotSupportedException {
		if (id != null && !id.isEmpty()) {
			Computer computer = computerMap.get(id);
			return (Computer) computer.clone();
		}
		return null;
	}

}